package com.edu.aspect;



import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Date;

/*
 * @Author:mx
 * @Date:2025/11/12-9:41:49
 */
/*
*       MyAdvise 通知类
*       @Component 表示把这个类的对象放在容器里
*       @Aspect 表示当前类 是一个切面
*
* */
@Component
@Aspect
@Order(1)
public class MyAdvise {

    @Pointcut("execution(* com.edu.service..*.*(..))")
    public void pt1(){}

    @Before("pt1()")
    public void beforeAdvise(JoinPoint jp){
//        System.out.println(jp.getSignature().getName());
        System.out.println("执行了前置通知1");
    }

    @AfterReturning(pointcut = "pt1()",returning = "result")
    public void afterReturnAdvise(JoinPoint jt,Object result){
        System.out.println("业务方法 原始返回值:"+result);
        System.out.println("执行了后置返回通知");
    }

    @AfterThrowing(pointcut = "pt1()",throwing = "e")
    public void afterThrowAdvise(JoinPoint jt,Exception e){
        System.out.println("异常类型:"+e+e.getClass());
        System.out.println("后置异常通知");
    }

    @After("pt1()")
    public void afterAdvise(JoinPoint jp){
        System.out.println("执行了后置通知");
    }

    @Around("pt1()")
    public Object aroundAdvise(ProceedingJoinPoint pjp){
        System.out.println("环绕通知前置");
        Object obj  = null;
        try {
            obj = pjp.proceed(pjp.getArgs());

        } catch (Throwable e) {
            e.printStackTrace();
        }
        System.out.println("环绕通知后置");
        return obj;
    }


}
